$(function() {
	$('#username').focus();
	$("#login_form").submit(function()	{
		$("#msgbox").removeClass().addClass('messagebox').text('Validasi data...').fadeIn(1000);		
		if ($('#username').val() == '') {
			$("#msgbox").fadeTo(200,0.1,function() { 
				$(this).html('Username wajib diisi...').addClass('messageboxerror').fadeTo(900,1);
			});
			$('#username').focus();
		} else if ($('#password').val() == '') {
			$("#msgbox").fadeTo(200,0.1,function() { 
				$(this).html('Password wajib diisi...').addClass('messageboxerror').fadeTo(900,1);
			});
			$('#password').focus();
		/*} else if ($('#status').val() == 0) {
			$("#msgbox").fadeTo(200,0.1,function() { 
				$(this).html('Status login wajib diisi...').addClass('messageboxerror').fadeTo(900,1);
			});*/
		} else {
			$.post(base_url+"login/cek",{
				username:$('#username').val(),
				password:$('#password').val(),
				//status:$('#status').val(), 
				//status2:$('#status2').val(),
				rand:Math.random()
				} ,
				function(data) {
					if (data == 'account found') {
					$("#msgbox").fadeTo(200,0.1,function() {
						$(this).html('Login berhasil... bersiap membuka sistem...').addClass('messageboxok').fadeTo(900,2,function() {
							document.location=base_url+'beranda';
						});
					});
					} else if (data=='account found more than one') {
						$("#msgbox").fadeTo(200,0.1,function() {
						$(this).html('Login berhasil... bersiap membuka sistem...').addClass('messageboxok').fadeTo(900,2,function() {
							document.location=base_url+'beranda/menu.otoritas';
						});
					});
					} else if (data=='admin found') {
						$("#msgbox").fadeTo(200,0.1,function() {
						$(this).html('Login berhasil... bersiap membuka sistem...').addClass('messageboxok').fadeTo(900,2,function() {
							document.location=base_url+'beranda';
						});
					});
					} else if(data=='account not found') {
						$("#msgbox").fadeTo(200,0.1,function() { 
							$(this).html('Username atau Password masih salah...').addClass('messageboxerror').fadeTo(900,1);
						});
					} else if(data=='noserver') {
						$("#msgbox").fadeTo(200,0.1,function() { 
							$(this).html('Tidak ada respon dari server...').addClass('messageboxerror').fadeTo(900,1);
						});
					}
				});
			/*if (($('#status').val() == 'Mahasiswa' || $('#status').val() == 'alumni')) {
				var fak	= $('#fak :selected').text();
				var jurusan = '';
				if ($('#jur1').val() != 0) {
					jurusan = $('#jur1 :selected').text();
				} else if ($('#jur2').val() != 0) {
					jurusan = $('#jur2 :selected').text();
				} else if ($('#jur3').val() != 0) {
					jurusan = $('#jur3 :selected').text();
				}
				$.post("login.cek",{username:$('#username').val(),password:$('#password').val(),status:$('#status').val(),fak:fak,jurusan:jurusan,rand:Math.random()} ,function(data) {
					if (data == 'yes_staff') {
						$("#msgbox").fadeTo(200,0.1,function() {
							$(this).html('Login berhasil... bersiap membuka sistem...').addClass('messageboxok').fadeTo(900,2,function() {
								document.location='staff';
							});
						});
					} else if (data=='yes') {
						$("#msgbox").fadeTo(200,0.1,function() {
							$(this).html('Login berhasil... bersiap membuka sistem...').addClass('messageboxok').fadeTo(900,2,function() {
								document.location='layout';
							});
						});
					} else if(data=='no') {
						$("#msgbox").fadeTo(200,0.1,function() { 
							$(this).html('Username atau Password masih salah...').addClass('messageboxerror').fadeTo(900,1);
						});
					} else if(data=='noserver') {
						$("#msgbox").fadeTo(200,0.1,function() { 
							$(this).html('Tidak ada respon dari server...').addClass('messageboxerror').fadeTo(900,1);
						});
					}
				});
			} else {
				$.post("login.cek",{
					username:$('#username').val(),
					password:$('#password').val(),
					status:$('#status').val(), 
					status2:$('#status2').val(),
					rand:Math.random()
					} ,
					function(data) {
							if (data == 'yes_staff') {
							$("#msgbox").fadeTo(200,0.1,function() {
								$(this).html('Login berhasil... bersiap membuka sistem...').addClass('messageboxok').fadeTo(900,2,function() {
									document.location='staff';
								});
							});
							} else if (data=='yes') {
								$("#msgbox").fadeTo(200,0.1,function() {
								$(this).html('Login berhasil... bersiap membuka sistem...').addClass('messageboxok').fadeTo(900,2,function() {
									document.location='layout';
								});
							});
							} else if(data=='no') {
								$("#msgbox").fadeTo(200,0.1,function() { 
									$(this).html('Username atau Password masih salah...').addClass('messageboxerror').fadeTo(900,1);
								});
							} else if(data=='noserver') {
								$("#msgbox").fadeTo(200,0.1,function() { 
									$(this).html('Tidak ada respon dari server...').addClass('messageboxerror').fadeTo(900,1);
								});
							}
						});
			}*/			
		}		
		return false;
	});
});